package com.hzit.search.controller;

import com.hzit.search.entity.ItemVo;
import com.hzit.search.service.ItemSearchService;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;
import java.util.Map;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Controller
public class SearchController {
	@Autowired
	private ItemSearchService searchService;
	//1. 开始根据条件进行查询
	@GetMapping({"/","/search.html"})
	public String search(Model model, ItemVo vo) throws IOException {
		//1.1 开始进行查询
		Map resultMap = searchService.search(vo);
		//1.2 将查询结果放到model中
		model.addAttribute("resultMap",resultMap);
		model.addAttribute("vo",vo);
		return "search";
	}
}
